package me.chan.chatting.server.serialize;

import com.google.gson.Gson;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

public class JSONSerializer  implements Serializer {

    @Override
    public <T> byte[] serialize(T t) throws IOException {
        Gson gson = new Gson();
        String json = gson.toJson(t);
        return json.getBytes(StandardCharsets.UTF_8);
    }

    @Override
    public <T> T deserialize(Class<T> clazz, byte[] bytes) throws IOException {
        Gson gson = new Gson();
        return gson.fromJson(new String(bytes, StandardCharsets.UTF_8), clazz);
    }


    // class
}
